.section .data
.globl FrameBufferStruct
FrameBufferStruct:
	.int 800  /* 0 Width */
	.int 600  /* 4 Height */
	.int 800  /* 8 Virtual width */
	.int 600  /* 12 Virtual height */
	.int 0    /* 16 pitch : set by the GPU */
	.int 16   /* 20 depth */
	.int 0    /* 24 X-offset */
	.int 0    /* 28 Y-offset */
	.int 0    /* 32 Ptr, set by the GPU */
	.int 0    /* 36 Frame buffer size, set by the GPU */
.section .text
.globl InitialiseFrameBuffer
InitialiseFrameBuffer:
	push {r5, r6, r7, r8, lr}
	width .req r6
	height .req r7
	depth .req r8
	mov width, r0
	mov height, r1
	mov depth, r2
	fbsAddress .req r5
	ldr fbsAddress, =FrameBufferStruct
	ldr width, [fbsAddress]
	ldr width, [fbsAddress,#8]
	ldr height, [fbsAddress, #4]
	ldr height, [fbsAddress, #12]
	ldr depth, [fbsAddress, #20]
	mov r0, fbsAddress
	mov r1, #1 /* Le channel 1 correspond au Framebuffer */
	bl MBSendMsg
	mov r0, #1
	bl MBReadMsg
	teq r0, #0
	popeq {r5, pc} /* Erreur : r0 vaut 0 */
	wait_ptr:
		ldr r0, =250000
		bl OKLedBlink
		ldr r0, [fbsAddress, #32]
		teq r0, #0
		beq wait_ptr
	mov r0, fbsAddress	
	.unreq fbsAddress
	.unreq width
	.unreq height
	.unreq depth
	pop {r5, r6, r7, r8, pc}
